package com.franzliszt.maillist.sql;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class Helper extends SQLiteOpenHelper {
    /**数据库名称*/
    public static final String DataBase = "MailList.db";
    public static final SQLiteDatabase.CursorFactory factory = null;
    public static int version = 1;
    /**表名*/
    public static final String TableName = "Contacts";
    /**行名*/
    public static final String Row_LastName = "LastName";
    public static final String Row_FirstName = "FirstName";
    public static final String Row_PinYin = "PinYin";
    public static final String Row_Phone = "PhoneNumber";
    public static final String Row_School = "School";
    public static final String Row_Address = "Address";
    public static final String Row_Other = "Other";



    public Helper(@Nullable Context context) {
        super( context, DataBase, factory, version );
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "create table " + TableName + "( "+Row_Phone+" varchar(20) primary key, "+Row_LastName+" varchar(20),"+Row_FirstName+" varchar(20),"+Row_PinYin+" varchar(20), "+Row_School+" varchar(20),"+Row_Address+" varchar(20),"+Row_Other+" varchar(20));";
        db.execSQL( sql );
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table if exists "+TableName);
        onCreate(db);
    }
}
